package com.hugong.yxx.wksp.modules.controller;

import com.baomidou.mybatisplus.plugins.Page;
import com.hugong.yxx.wksp.common.utils.HttpContextUtils;
import com.hugong.yxx.wksp.persistence.entity.User;

import javax.servlet.http.HttpSession;
import java.util.Map;

/**
 * @Description
 * @Author by yxx
 * @Create 2019-01-08 16:00
 */

public abstract class BaseController {

    static Page<Map<String, Object>> createPage(Integer page, Integer pageSize) {
        page = page != null ? page : 1;
        pageSize = pageSize != null ? pageSize : 10;
        Page<Map<String, Object>> pagination = new Page<>(page, pageSize);
        //不进行count sql优化，解决MP无法自动优化SQL问题
        pagination.setOptimizeCountSql(false);
        //查询总记录数
        pagination.setSearchCount(true);
        return pagination;
    }

    public static User getUser() {
        return (User) HttpContextUtils.getHttpServletRequest().getSession().getAttribute("user");
    }

    public static Integer getUserId() {
        return getUser().getUserID();
    }

    public static HttpSession getSession(){
        return HttpContextUtils.getHttpServletRequest().getSession();
    }
}
